home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 249 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.5 KB

  1. From: fjh@munta.cs.mu.OZ.AU (Fergus Henderson)
  2. Message-ID: <9602020715.21371@mulga.cs.mu.OZ.AU>
  3. X-Original-Date: Fri, 2 Feb 1996 18:15:24 +1100
  4. Path: in1.uu.net!bounce-back
  5. Date: 03 Feb 96 04:41:29 GMT
  6. Approved: fjh@cs.mu.oz.au
  7. Newsgroups: comp.std.c++
  8. Subject: Re: Give operator. a chance
  9. Organization: Computer Science, University of Melbourne, Australia
  10. References: <3102AD11.1663@et.se> <4e0pj1$rq6@news.bridge.net> <9601260532.14152@mulga.cs.mu.OZ.AU> <4eqr6b$778@s3.iway.fr>
  11. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  12.     iQBFAgUBMRLnhuEDnX0m9pzZAQG6pgF7BWEySxerVKEcSqvqkDmV/fIhHy//sp6b
  13.     pYaDg/dNn2f0kk77Js8NRjJDJ10IWZTg
  14.     =KUYH
  15.  
  16. Valentin Bonnard <bonnardv@pratique.fr> writes:
  17.  
  18. >First of all, I suppose there is no difference bewten A + B, A.operator+ (B)
  19. >and A.plus (B) when operator+ is defined as plus.
  20.  
  21. No, not in the semantics which Jim Adcock proposed and which I implemented.
  22. The rule is very simple: you invoke the `operator . ()' function, if any,
  23. if and only if the source code contains a `.'.  So `A.operator+(B)' and
  24. `A.plus(B)' will invoke `operator . ()', but `A + B' will not.
  25.  
  26. >Suppose first you overload operator+, then you overload operator. in MyClass:
  27. [...]
  28. >MyClass A;
  29. >
  30. >A + 2; is equivalent with A.operator (2) and (A.operator.).operator (2)
  31.  
  32. Nope, according to Jim Adcock's proposal, `A + 2' would not invoke the
  33. user-defined `operator . ()' function.  See above.
  34.  
  35. >You can't even write (&A)->Something_only_defined_in_MyClass () in order to
  36. >access Something_only_defined_in_MyClass (which is only defined for MyClass):
  37.  
  38. Nope, according to Jim Adcock's proposal, for your example you are free to
  39. do so.
  40.  
  41. >Note that A.m _is equivalent_ (provided that operator. is not overloaded in 
  42. >AnnotherClass) with (&A)->m.
  43.  
  44. Nope, according to Jim Adcock's proposal that is not necessarily true either.
  45. This is just like `x++' not necessarily being equivalent to `x = x + 1'
  46. if you have overloaded `operator ++'.
  47.  
  48. With Jim Adcock's proposal, if you overload `operator .', you can make
  49. the equivalence hold, by also overloading `operator &' to return a
  50. smart pointer class.  Without his proposal, if you overload `operator &',
  51. in the general case there is no way to make the equivalence hold.
  52.  
  53. --
  54. Fergus Henderson                 WWW: http://www.cs.mu.oz.au/~fjh
  55. fjh@cs.mu.oz.au                  PGP: finger fjh@128.250.37.3
  56. ---
  57. [ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  58.   Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  59.   is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
  60.